//统一管理项目用户相关的接口
import request from '@/utils/request'
import axios from 'axios'

//项目用户相关的请求地址
enum API {
  LOGIN_URL = '/login',
  REGISTER_URL = '/register',
  USERINFO_URL = '/user/userInfo',
  LOGOUT_URL = '/admin/acl/index/logout',
  CAPTCHA_URL = 'api/captcha',
  FIND_URL = '/admin/find',
  ADD_URL = '/admin/add',
  MODIFY_URL = '/admin/modify',
  DELETE_URL = '/admin/delete',
}
//对外暴露请求函数
//查询所有用户方法
export const reqUserFind = (data: any = {}) => {
  return request.post<any, any>(API.FIND_URL, data)
}

//添加用户方法
export const reqAddUser = (data: any) => {
  return request.post<any, any>(API.ADD_URL, data)
}

//修改用户方法
export const reqModifyUser = (data: any) => {
  return request.post<any, any>(API.MODIFY_URL, data)
}

//删除用户方法
export const reqDeleteUser = (data: {userId: string}) => {
  return request.delete<any, any>(API.DELETE_URL, { data })
}

//注册接口方法
export const reqRegister = (data: any) => {
  return request.post<any, any>(API.REGISTER_URL, data)
}

//登录接口方法
export const reqLogin = (data: any) => {
  return request.post<any, any>(API.LOGIN_URL, data)
}

//获取用户信息接口方法
export const reqUserInfo = () => {
  return request.get<any, any>(API.USERINFO_URL)
}

//退出登录
export const reqLogout = () => {
  return request.post<any, any>(API.LOGOUT_URL)
}

//获取验证码
export const reqCaptcha = () => {
  return axios.get(API.CAPTCHA_URL, {
    baseURL: import.meta.env.VITE_APP_BASE_API,
    responseType: 'blob',
    headers: {
      'Accept': 'image/*'
    }
  })
}
